home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / ui / checkbox.c < prev    next >
C/C++ Source or Header  |  1998-08-08  |  3KB  |  123 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13.  
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #include "mem.h"
  18. #include "fix.h"
  19. #include "types.h"
  20. #include "gr.h"
  21. #include "ui.h"
  22. #include "key.h"
  23.  
  24. #define Middle(x) ((2*(x)+1)/4)
  25.  
  26. void ui_draw_checkbox( UI_GADGET_CHECKBOX * checkbox )
  27. {
  28.  
  29.     if ((checkbox->status==1) || (checkbox->position != checkbox->oldposition))
  30.     {
  31.         checkbox->status = 0;
  32.  
  33.         ui_mouse_hide();
  34.         gr_set_current_canvas( checkbox->canvas );
  35.  
  36.         if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)checkbox)
  37.             gr_set_fontcolor( CRED, -1 );
  38.         else
  39.             gr_set_fontcolor( CBLACK, -1 );
  40.  
  41.         if (checkbox->position == 0 )
  42.         {
  43.             ui_draw_box_out( 0, 0, checkbox->width-1, checkbox->height-1 );
  44.             if (checkbox->flag)
  45.                 ui_string_centered(  Middle(checkbox->width), Middle(checkbox->height), "X" );
  46.             else
  47.                 ui_string_centered(  Middle(checkbox->width), Middle(checkbox->height), " " );
  48.         } else {
  49.             ui_draw_box_in( 0, 0, checkbox->width-1, checkbox->height-1 );
  50.             if (checkbox->flag)
  51.                 ui_string_centered(  Middle(checkbox->width)+1, Middle(checkbox->height)+1, "X" );
  52.             else
  53.                 ui_string_centered(  Middle(checkbox->width)+1, Middle(checkbox->height)+1, " " );
  54.         }
  55.  
  56.         gr_ustring( checkbox->width+4, 2, checkbox->text );
  57.  
  58.         ui_mouse_show();
  59.     }
  60. }
  61.  
  62.  
  63. UI_GADGET_CHECKBOX * ui_add_gadget_checkbox( UI_WINDOW * wnd, short x, short y, short w, short h, short group, char * text )
  64. {
  65.     UI_GADGET_CHECKBOX * checkbox;
  66.  
  67.     checkbox = (UI_GADGET_CHECKBOX *)ui_gadget_add( wnd, 5, x, y, x+w-1, y+h-1 );
  68.  
  69.     checkbox->text = malloc(strlen(text)+5);
  70.     strcpy(checkbox->text,text);
  71.     checkbox->width = w;
  72.     checkbox->height = h;
  73.     checkbox->position = 0;
  74.     checkbox->oldposition = 0;
  75.     checkbox->pressed = 0;
  76.     checkbox->flag = 0;
  77.     checkbox->group = group;
  78.  
  79.     return checkbox;
  80.  
  81. }
  82.  
  83.  
  84. void ui_checkbox_do( UI_GADGET_CHECKBOX * checkbox, int keypress )
  85. {
  86.     int OnMe, ButtonLastSelected;
  87.  
  88.     keypress = keypress;
  89.  
  90.     OnMe = ui_mouse_on_gadget( (UI_GADGET *)checkbox );
  91.  
  92.     checkbox->oldposition = checkbox->position;
  93.  
  94.     if ((selected_gadget != NULL) && (selected_gadget->kind !=5))
  95.         ButtonLastSelected = 0;
  96.     else
  97.         ButtonLastSelected = 1;
  98.  
  99.     if ( B1_PRESSED && OnMe && ButtonLastSelected )
  100.     {
  101.         checkbox->position = 1;
  102.     } else  {
  103.         checkbox->position = 0;
  104.     }
  105.  
  106.  
  107.     if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)checkbox) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
  108.         checkbox->position = 2;
  109.  
  110.     if ((checkbox->position==0) && (checkbox->oldposition==1) && OnMe )
  111.         checkbox->pressed = 1;
  112.     else if ((checkbox->position==0) && (checkbox->oldposition==2) && (CurWindow->keyboard_focus_gadget==(UI_GADGET *)checkbox) )
  113.         checkbox->pressed = 1;
  114.     else
  115.         checkbox->pressed = 0;
  116.  
  117.     if (checkbox->pressed == 1)
  118.         checkbox->flag ^= 1;
  119.  
  120.     ui_draw_checkbox( checkbox );
  121.  
  122. }
  123.